var orderHandler = {
    search: function (pageIndex) {
        $("input[name=pageIndex]").val(pageIndex);
        $("#searchForm").submit();
    },
    searchAll: function () {
        window.location.href = pageUri;
    },
    illnessDesc: function (orderId) {
        var desc = $("#illnessDesc_" + orderId).val();
        illnessModal.show(function () {
            $("#illness_content").text(desc);
        })
    },
    detail: function (orderId) {
        var uri = orderApiUri + "/detail?orderId=" + orderId;
        hot.newTab(uri, "订单-" + orderId + "详情");
    },
    confirm: function (orderId) {
        hot.confirm("确认要执行次操作？", function () {
            hot.ajax(orderApiUri + "/confirm", {
                orderId: orderId
            }, function (apiResult) {
                if (apiResult.resultCode == 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败");
                }
            }, function () {
            }, "post", 300);
        })
    },
    close: function (orderId) {
        hot.confirm("确定要关闭次订单，订单将无法进行任何操作", function () {
            hot.ajax(orderApiUri + "/close", {
                orderId: orderId
            }, function (apiResult) {
                if (apiResult.resultCode == 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败");
                }
            }, function () {
            }, "post", 300);
        })
    },
    complete: function (orderId) {
        hot.confirm("确定要完成该订单，订单将无法进行任何操作", function () {
            hot.ajax(orderApiUri + "/complete", {
                orderId: orderId
            }, function (apiResult) {
                if (apiResult.resultCode == 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败");
                }
            }, function () {
            }, "post", 300)
        })
    },
    book: function () {
        window.location.href = orderBookUri;
    }
};

var medicalStaffHandler = {
    sel: function (orderId) {
        $("#currentAssignOrderId").val(orderId);
        hot.iframeModal(selMedicalStaffUri + "?enableInquiry=true", '880px', '600px', "选择执行人员");
    },
    setMedicalStaff: function (medicalStaffId, medicalStaffName) {
        var assignUri = assignConfirmUri + "?medicalStaffId=" + medicalStaffId + "&orderId=" + $("#currentAssignOrderId").val();
        hot.iframeModal(assignUri, "880px", '600px', "确定计划开始时间");
    }
};

var assignHandler = {
    assign: function (medicalStaffId, planedStartTime) {
        var orderId = $("#currentAssignOrderId").val();
        var requestData = {
            orderId: orderId,
            medicalStaffId: medicalStaffId,
            planedStartTime: planedStartTime
        };
        hot.ajax(orderApiUri + "/assign", requestData, function (apiResult) {
            if (apiResult.resultCode === 2000) {
                hot.tip.success("指派成功", function () {
                    window.location.reload();
                })
            } else {
                hot.tip.error("指派失败--" + apiResult.resultMsg);
            }
        }, function () {
        }, "post", 300);
    }
};